#include <iostream>
using namespace std;

// 抽象不同零件类
// 抽象CPU类
class CPU
{
public:
    //抽象的计算函数
    virtual void calculate() = 0;
};

// 抽象显卡类
class VideoCard
{
public:
    //抽象的显示函数
    virtual void display() = 0;
};

// 抽象内存条类
class Memory
{
public:
    //抽象的存储函数
    virtual void storage() = 0;
};

// 电脑类
class Computer
{
public:
    Computer(CPU* cpu, VideoCard* videocard, Memory* memory)
    {
        this->cpu = cpu;
        this->videocard = videocard;
        this->memory = memory;
    }

    void work()
    {
        cpu->calculate();
        videocard->display();
        memory->storage();
    }

    //提供析构函数 释放三个电脑零件
    // ~Computer()
    // {
    //     if (cpu != NULL)
    //     {
    //         delete cpu;
    //         cpu = NULL;
    //     }
    //     if (videocard != NULL)
    //     {
    //         delete videocard;
    //         videocard = NULL;
    //     }
    //     if (memory != NULL)
    //     {
    //         delete memory;
    //         memory = NULL;
    //     }
    // }
private:
    CPU* cpu;
    VideoCard* videocard;
    Memory* memory;
};

//具体厂商
//Intel厂商
class IntelCPU:public CPU
{
public:
    void calculate()
    {
        cout << "Intel的CPU开始计算了！" << endl;
    }
};
class IntelVideoCard:public VideoCard
{
public:
    void display()
    {
        cout << "Intel的VideoCard开始显示了！" << endl;
    }
};
class IntelMemory:public Memory
{
public:
    void storage()
    {
        cout << "Intel的storage开始存储了！" << endl;
    }
};

//Lenovo厂商
class LenovoCPU:public CPU
{
public:
    void calculate()
    {
        cout << "Lenovo的CPU开始计算了！" << endl;
    }
};
class LenovoVideoCard:public VideoCard
{
public:
    void display()
    {
        cout << "Lenovo的VideoCard开始显示了！" << endl;
    }
};
class LenovoMemory:public Memory
{
public:
    void storage()
    {
        cout << "Lenovo的storage开始存储了！" << endl;
    }
};

void test1()
{
    //电脑零件
    CPU* intelcpu = new IntelCPU;
    VideoCard* intelvideocard = new IntelVideoCard;
    Memory* intelmemory = new IntelMemory;

    CPU* lenovocpu = new LenovoCPU;
    VideoCard* lenovovideocard = new LenovoVideoCard;
    Memory* lenovomemory = new LenovoMemory;

    //创建第一台电脑
    Computer* computer1 = new Computer(intelcpu, intelvideocard, intelmemory);
    computer1->work();
    delete computer1;

    //创建第二台电脑
    cout << "---------------------------------" << endl;
    Computer* computer2 = new Computer(lenovocpu, intelvideocard, lenovomemory);
    computer2->work();
    delete computer2;

    //创建第三台电脑
    cout << "---------------------------------" << endl;
    Computer* computer3 = new Computer(intelcpu, lenovovideocard, intelmemory);
    computer3->work();
    delete computer3;
}

int main()
{
    test1();
    return 0;
}